@extends('admin.public.father')
@section('content')
    <div class="card">
        <table class="table table-hover" style="text-align: center">
            <thead>
            <tr>
                <th scope="col">编号</th>
                <th scope="col">标题</th>
                <th scope="col">作者</th>
                <th scope="col">发表时间</th>
                <th scope="col" width="200">操作</th>
            </tr>
            </thead>
            <tbody>
            @foreach($blogs as $v)
                <tr>
                    <th scope="row">{{$v['id']}}</th>
                    <td>{{$v['title']}}</td>
                    <td>{{$v->user->username}}</td>
                    <td>{{$v['created_at']}}</td>
                    <td>
                        <div class="btn-group">
                            <a href="{{route('blog.show',$v)}}" class="btn btn btn-primary">查看</a>
                            @can('update',$v)
                                <a href="{{route('blog.edit',$v)}}" class="btn btn-success">编辑</a>
                            @endcan
                            @can('delete',$v)
                                <form action="{{route('blog.destroy',$v)}}" method="post">
                                    @csrf
                                    @method('DELETE')
                                    <button type="submit" class="btn btn-danger">删除</button>
                                </form>
                            @endcan
                        </div>
                    </td>
                </tr>
            @endforeach
            </tbody>
        </table>
        {{--auth用于判断是否登录--}}
        @auth()
            <a href="{{route('blog.create')}}" class="btn btn-primary btn-lg btn-block" style="color: white">添加文章</a>
        @endauth
    </div>
    <div class="container">
        <div class="row justify-content-md-center">
            <div class="col-md-auto">
                {{--分页显示内容--}}
                {{ $blogs->links() }}
            </div>
        </div>
    </div>

@endsection